import {
  MongooseModule,
  Prop,
  Schema,
  SchemaFactory
} from '@nestjs/mongoose';
import { Document, Types } from 'mongoose';
import { ShareDocument } from '../document/share.document';

export type WebsitesDocument = Websites;

@Schema()
export class Websites extends ShareDocument {
  // 网站标题
  @Prop({
    unique: true,
    required: true,
  })
  title: string;

  // 网站地址
  @Prop({
    unique: true,
    required: true,
  })
  url: string;

  // 网站图标Url
  @Prop({
    default: '',
    required: true,
  })
  iconUrl: string;

  // 网站简介
  @Prop({
    default: ''
  })
  description: string;

  // 网站类型
  @Prop({
    ref: 'WebsiteTypes',
    required: true,
  })
  type: Types.ObjectId
}

export const WebsitesSchema = SchemaFactory.createForClass(Websites);

WebsitesSchema.set('toJSON', { getters: true });

export const WebsitesMongooseModule = MongooseModule.forFeature([
  { name: Websites.name, schema: WebsitesSchema },
]);
